using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Windows.Forms;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;
using EntLibContrib.PolicyInjection.CallHandlers;

namespace EntLibContrib.PolicyInjection.Tests
{
    [TestClass]
    public class CursorCallHandlerFixture
    {
        [TestMethod, DeploymentItem("CursorCallHandler.config")]
        public void Cursor_With_Config_Should_Change_According_To_Policy()
        {
            IConfigurationSource configurationSource = new FileConfigurationSource("CursorCallHandler.config");

            Foo foo = Microsoft.Practices.EnterpriseLibrary.PolicyInjection.PolicyInjection.Create<Foo>(configurationSource);

            Cursor.Current = Cursors.Hand;

            foo.Do();

            Assert.AreEqual(Cursor.Current, Cursors.Hand);
        }

        [TestMethod]
        public void Cursor_With_Attributes_Should_Change_According_To_Policy()
        {
            FooWithAttributes foo = Microsoft.Practices.EnterpriseLibrary.PolicyInjection.PolicyInjection.Create<FooWithAttributes>();

            Cursor.Current = Cursors.Hand;

            foo.Do();

            Assert.AreEqual(Cursor.Current, Cursors.Hand);
        }
    }

    public class Foo : MarshalByRefObject
    {
        public void Do()
        {
            Assert.AreEqual(Cursors.WaitCursor, Cursor.Current);
        }
    }

    [CursorCallHandler(Name = "WaitCursor")]
    public class FooWithAttributes : MarshalByRefObject
    {
        public void Do()
        {
            Assert.AreEqual(Cursors.WaitCursor, Cursor.Current);
        }
    }
}

